<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>商品详情</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <style type="text/css">
        .aui-bar-nav {
            /*padding: 0 11px 0 13px;
        box-sizing: border-box;*/
            top: 0;
            line-height: 2.25rem;
            background-color: #fff;
            color: #ffffff;
            border: none;
            background-size: 100% 1px;
            background-repeat: no-repeat;
            background-position: bottom;
            background-image: linear-gradient(0, #EEEEEE, #EEEEEE 50%, transparent 50%);
            background-image: -webkit-linear-gradient(90deg, #EEEEEE, #EEEEEE 50%, transparent 50%);
        }

        .aui-bar-nav .aui-btn .aui-iconfont {
            font-size: 0.9rem;
            line-height: 1.25rem;
            padding: 0;
            margin: 0;
            color: #000000;
        }

        .aui-bar-nav .aui-title {
            min-height: 2.25rem;
            position: absolute;
            margin: 0;
            text-align: center;
            white-space: nowrap;
            right: 5rem;
            left: 5rem;
            width: auto;
            overflow: hidden;
            text-overflow: ellipsis;
            z-index: 2;
            color: #333333;
            font-size: 17px;
            font-weight: bolder;
        }

        .aui-btn span {
            width: 22px;
            height: 22px;
        }

        .aui-btn span img {
            width: 22px;
            height: 22px;
        }

        .aui-bar-nav .aui-pull-right {
            padding: 0 11px;
            font-size: 0.8rem;
            font-weight: 400;
            z-index: 2;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-align-items: center;
            align-items: center;
        }

        button,
        .aui-btn {
            position: relative;
            display: inline-block;
            font-size: 0.7rem;
            font-weight: 400;
            font-family: inherit;
            text-decoration: none;
            text-align: center;
            margin: 0;
            background: #EEEEEE;
            padding: 0 15px!important;
            height: 1.5rem;
            line-height: 1.5rem;
            border-radius: 0.2rem;
            white-space: nowrap;
            text-overflow: ellipsis;
            vertical-align: middle;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            -webkit-user-select: none;
            user-select: none;
        }

        .aui-pull-right {
            font-size: 15px;
            color: #222222!important;
            text-align: right;
        }

        footer {
            width: 100%;
            padding: 0 17.5px;
            background: #fff!important;
            box-sizing: border-box;
            border: none;
            background-size: 100% 1px;
            background-repeat: no-repeat;
            background-position: top;
            background-image: linear-gradient(0, #EEEEEE, #EEEEEE 50%, transparent 50%);
            background-image: -webkit-linear-gradient(90deg, #EEEEEE, #EEEEEE 50%, transparent 50%);
            /*opacity: 0.1;*/
        }

        .aui-bar-tab {
            position: fixed;
            top: auto;
            /*padding: 5px 17.5px;*/
            table-layout: fixed;
            justify-content: space-between;
            display: flex;
            background-color: #fff!important;
        }

        .operation {
            display: flex;
            width: 100%;
            flex: 1;
            justify-content: space-between;
            align-items: center;
        }

        .operation div {
            flex: 1;
        }

        .operation div span {
            display: block;
            text-align: center;
            font-size: 12px;
            font-family: PingFang SC;
            font-weight: 400;
            color: #333333;
        }

        .operation div span.icon {
            display: block;
            width: 19px;
            height: 19px;
        }

        .operation div span.icon img {
            display: block;
            width: 100%;
            height: 100%;
        }

        .operation div span.text {
            margin-top: 3.5px;
            text-align: left;
        }

        .cashback {
            display: flex;
            width: 200px;
            margin-left: 28px;
            align-items: center;
        }

        .cashback_l {
            height: 40px;
            background: linear-gradient(-90deg, #FC3653, #F87721);
            border-radius: 20px 0px 0px 20px;
            flex: 1;
            line-height: 40px;
            color: #fff;
            font-size: 14px;
        }

        .cashback_l span {
            display: block;
            height: 15px;
            line-height: 15px;
            font-size: 14px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #FFFFFF;
        }

        .cashback_l span:first-child {
            margin-top: 3.5px;
        }

        .cashback_r {
            height: 40px;
            line-height: 40px;
            flex: 1;
            background: linear-gradient(-90deg, #7619EC, #A429F3);
            border-radius: 0px 20px 20px 0px;
            font-size: 14px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #FFFFFF;
        }

        .cashback_r span {
            display: block;
            height: 15px;
            line-height: 15px;
            font-size: 15px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #FFFFFF;
        }

        .cashback_r span:first-child {
            margin-top: 3.5px;
        }
    </style>
</head>

<body>
    <div id="app">
        <!-- <header class="aui-bar aui-bar-nav" id="header">
            <a class="aui-pull-left aui-btn" tapmode @click="closeWin()">
                <span>
                   <img src="../../image/back_arrow.png" alt="">
                </span>
            </a>
            <div class="aui-title">商品详情</div>
        </header> -->
        <footer class="aui-bar aui-bar-tab" id="footer">
            <div class="operation">
                <div class="operation_l" @click='backindex()'>
                    <span class="icon" style="margin:0 auto;"><img src="../../image/details_index_icon.png" alt=""></span>
                    <span class="text" style="text-align:center;">首页</span>
                </div>
                <div class="operation_l animated" tapmode @click='giveCollect()' style="margin-left:auto;">
                    <span class="icon" style="margin:0 auto;"><img :src="collectionImgStatus" alt=""></span>
                    <span class="text" style="text-align:center;">{{collectBottomText}}</span>
                </div>
            </div>
            <div class="cashback">
                <div class="cashback_l" @click='copyCommand()'>复制口令
                    <!-- <span>¥1.14</span> -->
                    <!-- <span style="margin-top:8px;">分享</span> -->
                </div>
                <div class="cashback_r" @click='GetCoupon()'>领券购买
                    <!-- <span>¥1.14</span>  -->
                    <!-- <span style="margin-top:8px;">领券购买</span> -->
                </div>
            </div>
        </footer>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/vue.js"></script>
<script type="text/javascript" src="../../script/cling.js"></script>
<script type="text/javascript">
    apiready = function() {
        cl.apiready();
        cl.openFrame({
            name: './goods_deatils_frame_',
            header: header,
            footer: footer,
            bounces: false,
            bgColor: "#FAF9F9",
            pageParam: {
                id: api.pageParam.id,
                index: api.pageParam.index
            }
        });

        vm.init(api.pageParam.id);

        api.addEventListener({
            name: 'keyback'
        }, function(ret, err) {
            if (ret) {
                cl.closeWin({
                    name: 'goods_deatils_'+api.pageParam.id
                });
                api.sendEvent({
                    name: 'backpage'
                });
            }
        });

        // vm.getCommand();




        /**
         * [监听登录成功事件]
         * @type {String}
         */
        api.addEventListener({
            name: 'login_success'
        }, function(ret, err) {
            if (ret) {
                var token = ret.value.token;
                var mid = ret.value.id;
                $api.setStorage('userToken', token);
                cl.userToken = $api.getStorage('userToken')
                $api.setStorage('mid', mid);
                cl.mid = $api.getStorage('mid')
                api.ajax({
                    url: cl.apiServer + 'member/getInfo/' + mid,
                    method: 'get',
                    headers: {
                        token: token
                    }
                }, function(ret, err) {
                    if (ret) {
                        if (ret.code == 0) {
                            $api.setStorage('zfbAccount', ret.data.zfbAccount);
                            $api.setStorage('truename', ret.data.truename);
                            $api.setStorage('userInfo', ret.data);
                            cl.userInfo = $api.getStorage('userInfo')

                            cl.closeWin({
                                name: "code_login"
                            });
                        }
                    }
                });
            }
        });


    };
    var vm = new Vue({
        el: "#app",
        data: {
            cvalue:'',
            collectionImgStatus: '../../image/collection.png',
            collectBottomText: '收藏', //已收藏，收藏
        },
        methods: {
            backindex:function(){
              api.sendEvent({
                  name: 'backindex'
              });
              cl.closeToWin({
                  name: 'root'
              });
            },
            copyCommand: function() {

              api.ajax({
                  url: cl.apiServer + 'tb/getPrivilegeLink',
                  method: 'post',
                  headers: {
                      'Content-Type': 'application/json;charset=utf-8',
                      token: cl.userToken
                  },
                  data: {
                      body: {
                          goodsId: api.pageParam.id,
                          version:cl.deviceInfo().appVersion,
                          mobileInfo:cl.systemType()
                      }
                  }
              }, function(ret, err) {
                  if (ret) {
                      cl.openAlert({
                          title: '复制淘口令购买',
                          content:ret.data.tpwd,
                          rightBtnTitle: '立即复制'
                      }, function(res) {
                          if (res.eventType === "right") {
                              var clipBoard = api.require('clipBoard');
                              clipBoard.set({
                                  value:ret.data.tpwd
                              }, function(ret, err) {
                                  if (ret) {

                                  }
                              });
                              cl.toast({
                                  msg: '已复制到剪切板'
                              });

                          }
                      })

                  }
              });



            },
            init: function(id) {
                api.ajax({
                    url: cl.apiServer + 'tb/getGoodsDetails',
                    method: 'post',
                    headers: {
                        'Content-Type': 'application/json;charset=utf-8',
                        token: cl.userToken
                    },
                    data: {
                        body: {
                            goodsId: id,
                            mid: cl.mid,
                            version:cl.deviceInfo().appVersion,
                            mobileInfo:cl.systemType()
                        }
                    }
                }, function(ret, err) {
                    console.log(JSON.stringify(ret))
                    if (ret) {
                        if (ret.code == 0) {
                            if (ret.data.GoodsDetailsVO.isCollection == 0) {
                                vm.collectBottomText = '收藏'
                                vm.collectionImgStatus = '../../image/collection.png';
                            } else {
                                vm.collectBottomText = '已收藏'
                                vm.collectionImgStatus = '../../image/collect_active.png';
                            }
                        }
                    }
                })
            },
            /**
             * [收藏]
             * @return {[type]} [description]
             */
            giveCollect: function() {
              if (!$api.getStorage('userToken')) {
                  cl.openWin({
                      name: '../login/code_login'
                  })
                  return;
              }
                if (vm.collectionImgStatus == '../../image/collect_active.png') {
                    vm.collectionImgStatus = '../../image/collection.png'
                    vm.collectBottomText = '收藏';
                    api.ajax({
                        url: cl.apiServer + 'collectProducts/cancelCollect',
                        method: 'post',
                        headers: {
                            'Content-Type': 'application/json;charset=utf-8',
                            token: cl.userToken
                        },
                        data: {
                            body: {
                                ids: [api.pageParam.id],
                                memberId: cl.mid,
                                version:cl.deviceInfo().appVersion,
                                mobileInfo:cl.systemType()
                            }
                        }
                    }, function(ret, err) {
                        console.log(JSON.stringify(ret));
                        if (ret) {
                            if (ret.code == 0) {

                            }else if (ret.code == 401) {
                              cl.openWin({
                                  name: '../login/code_login'
                              })

                            }
                        }
                    })
                } else {
                    vm.collectionImgStatus = '../../image/collect_active.png';
                    vm.collectBottomText = '已收藏';
                    api.ajax({
                        url: cl.apiServer + 'collectProducts/saveCollect',
                        method: 'post',
                        headers: {
                            'Content-Type': 'application/json;charset=utf-8',
                            token: cl.userToken
                        },
                        data: {
                            body: {
                                mid: cl.mid,
                                productId: api.pageParam.id,
                                type: 0,
                                version:cl.deviceInfo().appVersion,
                                mobileInfo:cl.systemType()
                            }
                        }
                    }, function(ret, err) {
                        if (ret) {
                            console.log(JSON.stringify(ret));
                            if (ret.code == 0) {


                            }else if (ret.code == 401) {
                              cl.openWin({
                                  name: '../login/code_login'
                              })

                            }
                        }
                    });
                }

            },
            GetCoupon: function() {
                api.ajax({
                    url: cl.apiServer + 'tb/getPrivilegeLink',
                    method: 'post',
                    headers: {
                        'Content-Type': 'application/json;charset=utf-8',
                        token: cl.userToken
                    },
                    data: {
                        body: {
                            goodsId: api.pageParam.id,
                            version:cl.deviceInfo().appVersion,
                            mobileInfo:cl.systemType()
                        }
                    }
                }, function(ret, err) {
                    if (ret) {
                        console.log(JSON.stringify(ret));
                        if (ret.code == 0) {
                            cl.openWin({
                                name: '../../brower_',
                                pageParam: {
                                    link: ret.data.couponClickUrl,
                                    type: 1
                                }
                            });
                        }
                    }
                });
            },
            closeWin: function() {
                cl.closeWin({
                    name: 'goods_deatils'
                });



            },

        }
    })
</script>

</html>
